package org.example.fastproject.web.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.fastproject.core.bean.PageParam;
import org.example.fastproject.core.bean.ViewResult;
import org.example.fastproject.web.sys.model.SysLog;
import org.example.fastproject.web.sys.model.SysUser;
import org.example.fastproject.web.sys.model.vo.log.LogVo;
import org.example.fastproject.web.sys.service.SysLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author 王海舟
 * @since 2023-01-20 15:38:29
 */
@RestController
@RequestMapping("/sys/sysLog")
@Api(tags = "系统：日志管理")
public class SysLogController {
    @Resource
    private SysLogService logService;

    @PostMapping("/page")
    @ApiOperation("分页获取日志列表")
    @PreAuthorize("hasAuthority('log.page')")
    public ViewResult<Page<LogVo>> page(@RequestBody PageParam param){
        Page<LogVo> page = logService.page(param);
        return ViewResult.success(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过日志id获取日志信息")
    @PreAuthorize("hasAuthority('log.id')")
    public ViewResult<SysLog> getById(@PathVariable Long id){
        SysLog sysLog = logService.getById(id);
        return ViewResult.success(sysLog);
    }

}
